import * as actions from '../actions/index';

// 页面初始化数据
const initialState = {
  pageInfo: {
    ...window.FORCE,
    ...(window.ERROR || {}),
  },
  reloading: false,
  updating: false, // updating这个状态标识更新中，在project/root里面用到，因为resetChildPageState需要时间，时序会乱
  // 新手任务展开收起状态：true展开，false收起
  newbieTaskExpandStatus: null,
  newbieTaskStatus: null,
};
const defaultAction = {
  type: 'doNothing',
};

export default function index(state = initialState, action = defaultAction) {
  switch (action.type) {
    case actions.UPDATE_PAGE_INFO: {
      return { ...state, pageInfo: { ...state.pageInfo, ...action.data }, updating: true };
    }
    case actions.UPDATE_PAGE_INFO_END: {
      return { ...state, updating: false };
    }
    case actions.UPDATE_PAGE_INFO_FROM_PROJECT:
      action.data.pathResource = { ...state.pageInfo.pathResource };
      return { ...state, pageInfo: { ...state.pageInfo, ...action.data } };
    case actions.RELOAD_START: {
      return { ...state, reloading: true };
    }
    case actions.RELOAD_END: {
      return { ...state, reloading: false };
    }
    case actions.RECEIVE_NEWBIE_TASK_EXPAND_STATUS: {
      return { ...state, newbieTaskExpandStatus: action.data };
    }
    case actions.RECEIVE_NEWBIE_TASK_STATUS: {
      return { ...state, newbieTaskStatus: action.data };
    }
    case actions.UPDATE_PROJECT_TAB_COUNT: {
      return { ...state, pageInfo: { ...state.pageInfo, ...action.data } };
    }
    default:
      return state;
  }
}
